package com.redare.dev.smart.generator.service.utils;

import com.redare.dev.smart.generator.sdk.pojo.CodeRoot;
import com.redare.dev.smart.generator.sdk.pojo.Templates;
import com.redare.dev.smart.generator.sdk.pojo.Variables;
import com.redare.dev.smart.generator.service.constant.Defaults;

import java.util.List;


/**
 * Created by yangqy on 2019-12-24.
 */
public class GlobalDataHelper {

    private Variables variables;
    private Templates templates;

    private volatile static GlobalDataHelper globalDataHelper;

    private GlobalDataHelper() {
        this.variables = new Variables();
        this.templates = new Templates();
        init();
    }

    public static GlobalDataHelper getInstance() {
        if (globalDataHelper == null) {
            synchronized (GlobalDataHelper.class) {
                globalDataHelper = new GlobalDataHelper();
            }
        }
        return globalDataHelper;
    }

    public Variables getVariables() {
        return variables;
    }

    public Templates getTemplates() {
        return templates;
    }

    private void init() {
        if (templates != null && templates.getRoots().size() == 0) {
            List<CodeRoot> defaultTemplates = Defaults.getDefaultTemplates();
            templates.setRoots(defaultTemplates);
            variables.setIgnoreFields("id,createTime,updateTime,create_time,update_time,deleted");
        }
    }
}
